

#include "Test.h"

#if TEST_RF
#include "Debug.h"
#include "Led.h"

#include "Bsp.h"
#include "CardPort.h"
#include "CardPrivate.h"
#include "ISO14443p3a.h"


static int Test_ConnectTypeA(void){
	int ret;
	ISO14443AInfo_T a;
	ret = Port_Picc_Activate(Card_T_CpuA, PICC_Op_Activate, &a);
	if(ret){
//			DBG_PRINT("Port_Picc_Activate fail:%d\r\n", ret);
		DBG_WRITE("Port_Picc_Activate fail\r\n");
		return ret;
	}	
	uint8_t ats[16];
	ret = Port_Picc_Setup(Card_T_CpuA, &a, ats);
	if(ret){
//			DBG_PRINT("Port_Picc_Setup fail:%d\r\n", ret);
		DBG_PRINT("Port_Picc_Setup fail\r\n");
		return ret;
	}
	Port_Picc_Teardown();
	DBG_WRITE("Connect OK\r\n");
	return ret;
}


void TestRF(void){	
	int ret;
	
	DBG_WRITE("Test RF:\r\n");
	while(1){
		BSP_Sleep_Ms(10);
		Port_Picc_SetRf(1);
		BSP_Sleep_Ms(10);
//			ret = Port_Picc_Detect(Card_T_CpuA);
		ret = 0;
		if(ret){
			DBG_WRITE("Type A Present\r\n");
			Led_On(LedId_Greent);
			ret =Test_ConnectTypeA();
		}
		else{
			ret = Port_Picc_Detect(Card_T_CpuB);
			if(ret){
				DBG_WRITE("Type B Present\r\n");
				Led_On(LedId_Greent);
			}
			else{
				Led_Off(LedId_Greent);
			}
		}
		Port_Picc_SetRf(0);
	}
}
#endif 


